package Tools.Lighting;

import java.util.*;
import java.util.Map.Entry;

public class LightMapCell {
	
	private Map<ILight, Float> _lstIlluminations = new HashMap<ILight, Float>();
	
	private boolean _fullIlluminated = false;
	
	/** Add illumination 
	 * @param light - Light 
	 * @param illumination - Illumination 
	 */
	public void addIllumination(ILight light, float illumination) {
		_lstIlluminations.put(light, (illumination > 1.f) ? 1 :
			(illumination < 0.f) ? 0 : illumination);
	}
	
	/** Returns true if light is contains in this cell
	 * @param light - Light
	 * @return True if light is contains in this cell
	 */
	public boolean containsLight(ILight light) {
		return _lstIlluminations.containsKey(light);
	}
	
	/** Returns illumination by light
	 * @param light - Light
	 * @return Illumination 
	 */
	public float getIlluminationByLight(ILight light) {
		return _lstIlluminations.get(light);
	}
	
	/** Returns illumination 
	 * @return Illumination 
	 */
	public float getIllumination() {
		float ret = 0.f;
		
		if (!_fullIlluminated) {

			for (Entry<ILight, Float> entry : _lstIlluminations.entrySet())
				ret += entry.getValue();

			if (ret > 1.f)
				ret = 1.f;
			
			if (ret < 0.f)
				ret = 0.f;
			
		} else
			ret = 1.f;
		
		return ret;
	}
	
	/** Full illuminated cell */
	public void fullIlluminated() {
		_fullIlluminated = true;
	}
}
